package com.lhf.springcloud.service;

import com.lhf.springcloud.DAO.TeacherDao;
import com.lhf.springcloud.Entity.teacher.TeacherData;
import com.lhf.springcloud.Entity.YearTeacher;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;


/**
 * @ClassName: StorangeServiceImpl
 * @Description:
 * @Author: liuhefei
 * @Date: 2019/4/1
 * @blog: https://www.imooc.com/u/1323320/articles
 **/
@Service
public class TeacherServiceImpl {


    @Autowired
    private TeacherDao teacherDao;

    public void addCourse(List<TeacherData> course) {
        for (int i=0;i<course.size();i++){
            teacherDao.addCourse(course.get(i));
        }

    }

    public List<TeacherData> findAllData() {
        List<TeacherData> data = teacherDao.findAllData();
        return data;
    }
    public List<TeacherData> findTeacherNum() {

        List<TeacherData> teacherNum = teacherDao.findTeacherNum();

        return teacherNum;
    }
    public List<YearTeacher> findTeacherNumByYear() {
        Calendar date = Calendar.getInstance();
        String years = String.valueOf(date.get(Calendar.YEAR));
        Integer year = Integer.valueOf(years);
       List<YearTeacher> list= new ArrayList<>();
        for (int i=0;i<5;i++){
            YearTeacher yearTeacher = new YearTeacher();
            List<TeacherData> data = teacherDao.findTeacherNumByYear(String.valueOf(year-i));
            yearTeacher.setYear(String.valueOf(year-i));
            yearTeacher.setList(data);
            list.add(yearTeacher);
        }

        return list;
    }
}
